home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3.iso / chapter8 / rmvdflt.c < prev    next >
C/C++ Source or Header  |  1996-04-28  |  7KB  |  215 lines

  1.  
  2. #include <windows.h>  
  3. #include <stdio.h>
  4. #include "rmvdflt.h"
  5. #include "sqlext.h"  
  6. #include "odbcinst.h"  
  7.  
  8.  
  9. #if defined (WIN32)
  10.     #define IS_WIN32 TRUE
  11. #else
  12.     #define IS_WIN32 FALSE
  13. #endif
  14.  
  15. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  16. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  17. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  18.  
  19. HINSTANCE hInst;   // current instance
  20.  
  21. LPCTSTR lpszAppName = "MyApp";
  22. LPCTSTR lpszTitle   = "SQLRemoveDefaultDataSource()"; 
  23.  
  24.  
  25. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  26.  
  27.  
  28. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  29.                       LPTSTR lpCmdLine, int nCmdShow)
  30. {
  31.    MSG      msg;
  32.    HWND     hWnd; 
  33.    WNDCLASS wc;
  34.  
  35.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  36.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  37.    wc.cbClsExtra    = 0;                      
  38.    wc.cbWndExtra    = 0;                      
  39.    wc.hInstance     = hInstance;              
  40.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  41.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  42.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  43.    wc.lpszMenuName  = lpszAppName;              
  44.    wc.lpszClassName = lpszAppName;              
  45.  
  46.    if ( IS_WIN95 )
  47.    {
  48.       if ( !RegisterWin95( &wc ) )
  49.          return( FALSE );
  50.    }
  51.    else if ( !RegisterClass( &wc ) )
  52.       return( FALSE );
  53.  
  54.    hInst = hInstance; 
  55.  
  56.    hWnd = CreateWindow( lpszAppName, 
  57.                         lpszTitle,    
  58.                         WS_OVERLAPPEDWINDOW, 
  59.                         CW_USEDEFAULT, 0, 
  60.                         CW_USEDEFAULT, 0,  
  61.                         NULL,              
  62.                         NULL,              
  63.                         hInstance,         
  64.                         NULL               
  65.                       );
  66.  
  67.    if ( !hWnd ) 
  68.       return( FALSE );
  69.  
  70.    ShowWindow( hWnd, nCmdShow ); 
  71.    UpdateWindow( hWnd );         
  72.  
  73.    while( GetMessage( &msg, NULL, 0, 0) )   
  74.    {
  75.       TranslateMessage( &msg ); 
  76.       DispatchMessage( &msg );  
  77.    }
  78.  
  79.    return( msg.wParam ); 
  80. }
  81.  
  82.  
  83. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  84. {
  85.    WNDCLASSEX wcex;  
  86.  
  87.    wcex.style         = lpwc->style;
  88.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  89.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  90.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  91.    wcex.hInstance     = lpwc->hInstance;
  92.    wcex.hIcon         = lpwc->hIcon;
  93.    wcex.hCursor       = lpwc->hCursor;
  94.    wcex.hbrBackground = lpwc->hbrBackground;
  95.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  96.    wcex.lpszClassName = lpwc->lpszClassName;
  97.  
  98.    // Added elements for Windows 95.
  99.    //...............................
  100.    wcex.cbSize = sizeof(WNDCLASSEX);
  101.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  102.                             IMAGE_ICON, 16, 16,
  103.                             LR_DEFAULTCOLOR );
  104.             
  105.    return RegisterClassEx( &wcex );  
  106. }
  107.  
  108.  
  109. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  110. {
  111. static HWND hList = NULL;
  112.  
  113.    switch( uMsg )
  114.    {
  115.       case WM_CREATE :
  116.               {
  117.                  hList = CreateWindow( "LISTBOX", "",    
  118.                                        LBS_NOTIFY | WS_VSCROLL | 
  119.                                        WS_BORDER  | WS_CHILD | 
  120.                                        WS_VISIBLE | LBS_NOINTEGRALHEIGHT, 
  121.                                        0, 0, 
  122.                                        0, 0,  
  123.                                        hWnd,              
  124.                                        (HMENU)101,              
  125.                                        hInst,         
  126.                                        NULL               
  127.                                      );
  128.               }
  129.               break;
  130.  
  131.       case WM_SIZE :
  132.               MoveWindow( hList, 0, 0, LOWORD( lParam ), 
  133.                                        HIWORD( lParam ), TRUE );
  134.               break; 
  135.               
  136.       case WM_COMMAND :
  137.               switch( LOWORD( wParam ) )
  138.               {
  139.                  case IDM_TEST :
  140.                         {
  141.                            BOOL  bRet;
  142.                            UCHAR szLBStr[128];
  143.  
  144.                            // Call SQLRemoveDefaultDataSource() 
  145.                            // to remove the default data source.
  146.                            // ..................................
  147.                            bRet = SQLRemoveDefaultDataSource();
  148.  
  149.                            strcpy( szLBStr, 
  150.                                    "SQLRemoveDefaultDataSource() " );
  151.  
  152.                            // Display status to the user.
  153.                            // ...........................
  154.                            if( bRet )
  155.                            {
  156.                               strcat( szLBStr, "successful" );
  157.  
  158.                               SendMessage( hList, LB_ADDSTRING, 0, 
  159.                                           (LPARAM)szLBStr );
  160.                            }
  161.                            else
  162.                            {
  163.                               strcat( szLBStr, "not successful" );
  164.  
  165.                               SendMessage( hList, LB_ADDSTRING, 0, 
  166.                                           (LPARAM)szLBStr );
  167.                            }
  168.                         }
  169.                         break;
  170.  
  171.                  case IDM_ABOUT :
  172.                         DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  173.                         break;
  174.  
  175.                  case IDM_EXIT :
  176.                         DestroyWindow( hWnd );
  177.                         break;
  178.               }
  179.               break;
  180.       
  181.       case WM_DESTROY :
  182.               PostQuitMessage(0);
  183.               break;
  184.  
  185.       default :
  186.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  187.    }
  188.  
  189.    return( 0L );
  190. }
  191.  
  192.  
  193. LRESULT CALLBACK About( HWND hDlg,           
  194.                         UINT message,        
  195.                         WPARAM wParam,       
  196.                         LPARAM lParam)
  197. {
  198.    switch (message) 
  199.    {
  200.        case WM_INITDIALOG: 
  201.                return (TRUE);
  202.  
  203.        case WM_COMMAND:                              
  204.                if (   LOWORD(wParam) == IDOK         
  205.                    || LOWORD(wParam) == IDCANCEL)    
  206.                {
  207.                        EndDialog(hDlg, TRUE);        
  208.                        return (TRUE);
  209.                }
  210.                break;
  211.    }
  212.  
  213.    return (FALSE); 
  214. }
  215.